import 'package:enterprise_v6_app/app/components/custom_modele/custom_color_type_indicator.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_gradient_line.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_progress_comp_page.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_title_content_view.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/my_columnar_bar.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_icon_title_view.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_title_chart_page.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/data/common/apply_page_bean.dart';
import 'package:enterprise_v6_app/app/data/common/charts_pie.dart';
import 'package:enterprise_v6_app/app/modules/application/controller.dart';
import 'package:syncfusion_flutter_charts/charts.dart' as charts;
import 'package:syncfusion_flutter_gauges/gauges.dart';

///新应用主页面
class ApplyPage extends StatelessWidget {
  ApplyPage({super.key});

  final controller = Get.put(ApplyController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        height: Get.height,
        color: const Color(0xffF5F5F6),
        child: Stack(
          children: [
            Container(
              height: 480.w,
              decoration: const BoxDecoration(
                gradient: LinearGradient(begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [
                  Color(0xff5C82FF),
                  Color(0xffF5F5F6),
                ]),
              ),
            ),
            Container(
              margin: EdgeInsets.only(top: 60.w, left: 16.w, right: 16.w),
              child: Column(
                children: [
                  // 搜索模块
                  GetBuilder(
                      id: 'searchView',
                      init: controller,
                      builder: (_) {
                        return _getSearchView();
                      }),
                  AppGaps.vGap14,
                  Expanded(
                      child: SingleChildScrollView(
                    child: Column(
                      children: [
                        GetBuilder(
                          id: 'applyList',
                          init: controller,
                          builder: (_) {
                            return CustomTitleContentView(
                              titleEdgeInsets: EdgeInsets.only(left: 20.w, top: 15.w),
                              // 提示信息
                              title: _getReminderView(),
                              contentEdgeInsets: EdgeInsets.only(top: 10.w, bottom: 20.w),
                              // 应用模块信息
                              content: _getApplicationModuleView(),
                            );
                          },
                        ),
                        AppGaps.vGap14,
                        // 我的当前任务完成率
                        GetBuilder(
                            id: 'currentTask',
                            init: controller,
                            builder: (_) {
                              return _getCurrentTaskView();
                            }),
                        AppGaps.vGap14,
                        // 企业双重预防上周完成情况
                        GetBuilder(
                            id: 'preventionLastWeek',
                            init: controller,
                            builder: (_) {
                              return _getDoublePreventionLastWeekView();
                            }),
                        AppGaps.vGap14,
                        // 双重预防机制(当年)
                        // _getDoublePreventionThatYearView(),
                        // AppGaps.vGap14,
                        // 重大危险
                        // _buildMajorHazard(),
                        // AppGaps.vGap14,
                        // 特殊作业（当年）
                        // _getSpecialThatYearView(),
                        // AppGaps.vGap14,
                        // 智慧仓库
                        // _getSmartWarehouseView(),
                        // AppGaps.vGap14,
                      ],
                    ),
                  ))
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  ///获取搜索模块
  Widget _getSearchView() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Container(
          width: 280.w,
          height: 40.w,
          padding: EdgeInsets.only(left: 10.w),
          decoration: BoxDecoration(color: Colors.white.withOpacity(0.4), borderRadius: BorderRadius.all(Radius.circular(10.w))),
          child: Row(
            children: [
              SvgPicture.asset(
                AppImages.icon_location,
                width: 20.w,
                height: 20.w,
                // colorFilter: const ColorFilter.mode(Colors.white, BlendMode.srcIn),
              ),
              AppGaps.hGap4,
              SizedBox(
                width: 60.w,
                child: Text(
                  controller.currentPlace == null ? '' : controller.currentPlace!.locality ?? '',
                  style: TextStyle(
                    fontSize: 14.sp,
                    overflow: TextOverflow.ellipsis,
                    fontWeight: FontWeight.w500,
                    color: const Color(0xffffffff),
                  ),
                ),
              ),
              Container(
                color: const Color(0xffffffff),
                height: 20.w,
                width: 1.w,
              ),
              AppGaps.hGap16,
              Text(
                '请输入关键字查询',
                style: TextStyle(
                  fontSize: 14.sp,
                  overflow: TextOverflow.ellipsis,
                  fontWeight: FontWeight.w500,
                  color: const Color(0xffffffff),
                ),
              )
            ],
          ),
        ),
        SvgPicture.asset(
          AppImages.icon_bar_scanning,
          width: 20.w,
          height: 20.w,
          // colorFilter: const ColorFilter.mode(Colors.white, BlendMode.srcIn),
        ),
        SvgPicture.asset(
          AppImages.icon_bar_message,
          width: 20.w,
          height: 20.w,
          colorFilter: const ColorFilter.mode(Colors.white, BlendMode.srcIn),
        )
      ],
    );
  }

  /// 提示信息
  Widget _getReminderView() {
    return Row(
      children: [
        SvgPicture.asset(
          AppImages.icon_home_reminder,
          width: 40.w,
          height: 40.w,
        ),
        AppGaps.hGap10,
        Expanded(
          flex: 2,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  Text(
                    '1',
                    style: TextStyle(
                      fontSize: 18.sp,
                      fontWeight: FontWeight.w500,
                      color: const Color(0xff495061),
                    ),
                  ),
                  Text(
                    '天',
                    style: TextStyle(
                      fontSize: 14.sp,
                      fontWeight: FontWeight.w400,
                      color: const Color(0xff495061),
                    ),
                  ),
                ],
              ),
              Text(
                '已连续履职',
                style: TextStyle(
                  fontSize: 14.sp,
                  fontWeight: FontWeight.w400,
                  color: const Color(0xff495061),
                ),
              ),
            ],
          ),
        ),
        Expanded(flex: 3, child: _getWeatherView()),
      ],
    );
  }

  /// 获取天气信息
  Widget _getWeatherView() {
    if (controller.weather == null) {
      return Container();
    }
    return RichText(
      text: TextSpan(
        children: [
          WidgetSpan(child: _getWeatherPictures()),
          WidgetSpan(child: AppGaps.hGap10),
          TextSpan(
            text: controller.weather!.temperature!,
            style: TextStyle(
              height: 1.2,
              fontSize: 36.sp,
              fontWeight: FontWeight.w500,
              color: const Color(0xff262F38),
            ),
          ),
          TextSpan(
            text: '℃',
            style: TextStyle(
              height: 1.2,
              fontSize: 12.sp,
              fontWeight: FontWeight.w500,
              color: const Color(0xff262F38),
            ),
          ),
          WidgetSpan(child: AppGaps.hGap4),
          TextSpan(
            text: controller.weather!.weather!,
            style: TextStyle(
              height: 1.2,
              fontSize: 10.sp,
              fontWeight: FontWeight.w500,
              color: const Color(0xff262F38),
            ),
          ),
        ],
      ),
    );
  }

  /// 获取天气图片
  Widget _getWeatherPictures() {
    final String weather = controller.weather!.weather!;
    String icon = '';
    if (weather.contains('晴')) {
      icon = AppImages.icon_sunny;
    } else if (weather.contains('多云')) {
      icon = AppImages.icon_cloudy;
    } else if (weather.contains('雨')) {
      icon = AppImages.icon_rain;
    } else if (weather.contains('风')) {
      icon = AppImages.icon_wind;
    } else if (weather.contains('阴')) {
      icon = AppImages.icon_cloudy_day;
    }
    if (icon.isNotEmpty) {
      return SvgPicture.asset(
        icon,
        width: 40.w,
        height: 40.w,
      );
    }
    return SizedBox(
      width: 40.w,
      height: 40.w,
    );
  }

  /// 获取应用模块信息
  Widget _getApplicationModuleView() {
    return SingleChildScrollView(
      child: Wrap(
        // spacing: 10.w, // 主轴(水平)方向间距
        runSpacing: 24.w, // 纵轴（垂直）方向间距
        // alignment: WrapAlignment.start, //沿主轴方向居中
        direction: Axis.horizontal,
        children: controller.applyList.map<Widget>((item) {
          return SizedBox(
              width: 65.w,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  SvgPicture.asset(
                    item.iconPath,
                    height: 28.w,
                    width: 28.w,
                  ),
                  AppGaps.vGap8,
                  Text(
                    item.name,
                    style: TextStyle(
                      fontSize: 10.sp,
                      fontWeight: FontWeight.w400,
                      color: const Color(0xff646E79),
                    ),
                  ),
                ],
              )).clickOnce(() {
            controller.toModulePage(item);
          });
        }).toList(),
      ),
    );
  }

  /// 我的当前任务完成率
  Widget _getCurrentTaskView() {
    return CustomTitleChartPage(
      title: '我的当前任务完成率',
      child: ListView.builder(
        padding: EdgeInsets.zero,
        itemCount: controller.currentTask.length,
        shrinkWrap: true,
        physics: const NeverScrollableScrollPhysics(),
        itemBuilder: (BuildContext context, int index) {
          return CustomProgressComp(
            bgColor: const Color(0xffEFF7FF),
            height: 6.w,
            width: 319.w,
            isShowIcon: false,
            isShowTitle: false,
            topTitle: _getTaskTitleView(controller.currentTask[index]),
            linearGradient: LinearGradient(begin: Alignment.centerRight, end: Alignment.centerLeft, colors: [
              controller.currentTask[index].bgColor,
              controller.currentTask[index].bgColor.withOpacity(0.26),
            ]),
            value: controller.currentTask[index].value,
            title: controller.currentTask[index].name,
          );
        },
      ),
    );
  }

  /// 我的当前任务完成率标题信息
  Widget _getTaskTitleView(ApplyPageBean bean) {
    return Row(
      children: [
        SizedBox(
          width: 70.w,
          child: Text(
            bean.name,
            style: TextStyle(
              fontSize: 12.sp,
              fontWeight: FontWeight.w400,
              color: const Color(0xff333333).withOpacity(0.5),
            ),
          ),
        ),
        Icon(Icons.arrow_left_outlined, size: 20.sp, color: const Color(0xffFD6B6B)),
        Text(
          '${bean.value * 100}%',
          style: TextStyle(
            fontSize: 12.sp,
            fontWeight: FontWeight.w400,
            color: const Color(0xff495061),
          ),
        ),
        const Spacer(),
        Text(
          '${bean.completed}/${bean.totalNumber}',
          style: TextStyle(
            fontSize: 12.sp,
            fontWeight: FontWeight.w500,
            color: const Color(0xff417EFB),
          ),
        ),
      ],
    );
  }

  /// 企业双重预防上周完成情况
  Widget _getDoublePreventionLastWeekView() {
    return CustomTitleChartPage(
      titleView: Stack(
        alignment: Alignment.topRight,
        children: [
          const CustomIconTitleView(
            title: '企业双重预防上周完成情况',
          ),
          _getLevelIcon(),
        ],
      ),
      child: Container(
          alignment: Alignment.center,
          width: AppDimens.sw,
          // color: Colors.red,
          // height: 120.w,
          child: Row(
            children: controller.preventionLastWeek
                .map((item) => Expanded(
                        child: _buildPreventionLastWeekBar(
                      title: item.name,
                      value: item.value,
                      color: item.bgColor,
                    )))
                .toList(),
          )),
    );
  }

  /// 获取等级图标
  /// 0:差 1：中 2：良 3：优
  Widget _getLevelIcon() {
    String? icon;
    switch (controller.scoreLevel) {
      case 0:
        icon = AppImages.icon_bad;
        break;
      case 1:
        icon = AppImages.icon_average;
        break;
      case 2:
        icon = AppImages.icon_good;
        break;
      case 3:
        icon = AppImages.icon_excellent;
        break;
    }
    if (icon == null) {
      return Container();
    }
    return SvgPicture.asset(
      icon,
      width: 71.w,
      height: 48.w,
      // colorFilter: const ColorFilter.mode(Colors.white, BlendMode.srcIn),
    );
  }

  /// 双重预防上周完成情况饼图
  ///生成当前作业统计
  ///[title] 标题
  ///[value] 进度值
  ///[color] 显示颜色
  Widget _buildPreventionLastWeekBar({
    required String title,
    required double value,
    required Color color,
  }) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        SizedBox(
          height: 90.w,
          width: 90.w,
          child: SfRadialGauge(
            axes: <RadialAxis>[
              RadialAxis(
                  radiusFactor: 0.85,
                  axisLineStyle: AxisLineStyle(color: const Color(0xFFE0E4EB).withOpacity(0.8), thickness: 0.24, thicknessUnit: GaugeSizeUnit.factor),
                  showLabels: false,
                  showTicks: false,
                  startAngle: 270,
                  endAngle: 270,
                  pointers: <GaugePointer>[
                    RangePointer(
                        pointerOffset: 0.05, width: 0.15, value: value, cornerStyle: CornerStyle.bothCurve, color: color, sizeUnit: GaugeSizeUnit.factor),
                  ],
                  annotations: <GaugeAnnotation>[
                    GaugeAnnotation(
                        widget: Text(
                          '${value.toInt()}%',
                          style: TextStyle(color: color, fontWeight: FontWeight.w400, fontSize: 16.sp),
                        ),
                        positionFactor: 0.15,
                        angle: 90)
                  ])
            ],
          ),
        ),
        AppGaps.vGap4,
        Text(
          title,
          style: TextStyle(
            color: const Color(0xFFA0A7B5),
            fontWeight: FontWeight.w400,
            fontSize: 12.sp,
          ),
        ),
      ],
    );
  }

  /// 双重预防机制(当年)
  Widget _getDoublePreventionThatYearView() {
    return CustomTitleChartPage(
      title: '双重预防机制(当年)',
      child: Column(
        children: [
          Row(
            children: [
              Expanded(child: _getRiskPieChartView(title: '初始风险数', dataList: controller.initialPreventionThatYearRisk, tooltip: controller.initialTooltip)),
              Expanded(child: _getRiskPieChartView(title: '剩余风险数', dataList: controller.surplusPreventionThatYearRisk, tooltip: controller.surplusTooltip)),
              Expanded(child: _getRiskTitle())
            ],
          ),
          AppGaps.vGap20,
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              _riskTypeWidget('一般隐患', const Color(0xffFFCE24)),
              AppGaps.hGap20,
              _riskTypeWidget('重大隐患', const Color(0xffFD6B6B)),
            ],
          ),
          ColumnarBar.columnarBar(
            width: 5.w,
            height: 150.w,
            xAxisList: controller.hiddenDangerAxisList,
            yAxis: controller.hiddenDangerYAxis,
          )
        ],
      ),
    );
  }

  /// 获取风险饼图显示
  Widget _getRiskPieChartView({required String title, required List<ApplyPageBean> dataList, required charts.TooltipBehavior tooltip}) {
    return Column(
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            Container(
              width: 4.w,
              height: 16.w,
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.all(Radius.circular(2.w)),
                  gradient: const LinearGradient(
                      //渐变位置
                      begin: Alignment.topCenter,
                      end: Alignment.bottomCenter,
                      //渐变颜色[始点颜色, 结束颜色]
                      colors: [Color(0xff5F57DC), Color(0xffB0ABFB)])),
            ),
            Text(
              title,
              style: TextStyle(
                color: const Color(0xFF5F57DC),
                fontWeight: FontWeight.w400,
                fontSize: 14.sp,
              ),
            ),
          ],
        ),
        AppGaps.vGap10,
        SizedBox(
          height: 100.w,
          child: charts.SfCircularChart(
            series: <charts.CircularSeries>[
              charts.DoughnutSeries<ApplyPageBean, String>(
                dataSource: dataList,
                pointColorMapper: (ApplyPageBean data, _) => data.bgColor,
                xValueMapper: (ApplyPageBean data, _) => data.name,
                yValueMapper: (ApplyPageBean data, _) => data.completed,
                dataLabelSettings: const charts.DataLabelSettings(
                  isVisible: false,
                  labelPosition: charts.ChartDataLabelPosition.inside,
                ),
                radius: '100%',
                innerRadius: '65%',
                enableTooltip: true,
              ),
            ],
            tooltipBehavior: tooltip,
          ),
        )
      ],
    );
  }

  /// 风险右侧标题显示
  Widget _getRiskTitle() {
    return ListView.separated(
      padding: EdgeInsets.zero,
      physics: const NeverScrollableScrollPhysics(),
      shrinkWrap: true,
      itemCount: controller.initialPreventionThatYearRisk.length,
      itemBuilder: (context, index) {
        return Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              width: 10.w,
              height: 10.w,
              margin: EdgeInsets.only(right: 5.w),
              padding: EdgeInsets.all(2.w),
              decoration: BoxDecoration(color: controller.initialPreventionThatYearRisk[index].bgColor, borderRadius: BorderRadius.circular(5.w)),
              child: Container(
                decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(5.w)),
              ),
            ),
            Container(
              constraints: BoxConstraints(
                minWidth: 50.w, // 设置最小宽度
              ),
              child: Text(
                controller.initialPreventionThatYearRisk[index].name,
                style: TextStyle(fontSize: 12.w, fontWeight: FontWeight.w400, color: const Color(0xffA0A7B5)),
              ),
            ),
          ],
        );
      },
      separatorBuilder: (context, index) {
        return AppGaps.vGap10;
      },
    );
  }

  //安全风险实时统计 类型显示
  Widget _riskTypeWidget(String name, Color color) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Container(
          width: 8.w,
          height: 8.w,
          alignment: Alignment.center,
          decoration: BoxDecoration(
            borderRadius: BorderRadius.all(Radius.circular(40.w)),
            color: color,
          ),
        ),
        AppGaps.hGap10,
        Text(
          name,
          style: TextStyle(color: const Color(0xff333333), fontSize: 12.sp),
        ),
      ],
    );
  }

  /// 重大危险
  Widget _buildMajorHazard() {
    return CustomTitleChartPage(
      title: '重大危险',
      child: Column(
        children: [
          Container(
            decoration: BoxDecoration(
              color: const Color(0x1A5C6DFF),
              borderRadius: BorderRadius.circular(8.w),
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Row(
                  children: [
                    SizedBox(
                      width: 33.w,
                      height: 33.w,
                      child: Image.asset(AppImages.icon_task_list),
                    ),
                    AppGaps.hGap2,
                    Text(
                      '评价/评估报告',
                      style: TextStyle(
                        color: const Color(0xFF5C6DFF),
                        fontSize: 14.w,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                  ],
                ),
                Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    SizedBox(
                      width: 28.w,
                      height: 26.w,
                      child: Image.asset(AppImages.icon_green_dot),
                    ),
                    AppGaps.hGap2,
                    Text(
                      '正常',
                      style: TextStyle(
                        color: const Color(0xFF00CE78),
                        fontSize: 14.w,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                    AppGaps.hGap8,
                  ],
                )
              ],
            ),
          ),
          AppGaps.vGap20,
          Row(
            children: [
              _buildTitleLeftDot(),
              AppGaps.hGap4,
              Text(
                '全厂上个周期重大危险源包保责任完成情况',
                style: TextStyle(
                  color: const Color(0xFF5F57DC),
                  fontSize: 14.w,
                ),
              )
            ],
          ),
          AppGaps.vGap20,
          _buildHazardProgressTitle('主要负责人'),
          AppGaps.vGap10,
          CustomDividedProgress(
            vals: const [3, 4],
            colors: const [Colors.red, Colors.blue],
            total: 12,
          ),
          AppGaps.vGap20,
          _buildHazardProgressTitle('主要负责人'),
          AppGaps.vGap10,
          CustomDividedProgress(
            vals: const [3, 4],
            colors: const [Colors.red, Colors.blue],
            total: 12,
          ),
          AppGaps.vGap20,
          _buildHazardProgressTitle('主要负责人'),
          AppGaps.vGap10,
          CustomDividedProgress(
            vals: const [3, 4],
            colors: const [Colors.red, Colors.blue],
            total: 12,
          ),
          AppGaps.vGap20,
          Row(
            children: [
              _buildTitleLeftDot(),
              AppGaps.hGap4,
              Text(
                '当前报警统计',
                style: TextStyle(
                  color: const Color(0xFF5F57DC),
                  fontSize: 14.w,
                ),
              )
            ],
          ),
          AppGaps.vGap10,
          _buildRiskAnalysisInit(),
        ],
      ),
    );
  }

  /// 特殊作业（当年）
  Widget _getSpecialThatYearView() {
    return CustomTitleChartPage(
      title: '特殊作业（当年）',
      child: Column(
        children: [
          _buildSpecialWorkTop(),
          AppGaps.vGap20,
          _buildSpecialWorkColorTypeIndicator(),
          AppGaps.vGap16,
          _buildSpecialWorkChart(),
        ],
      ),
    );
  }

  /// 智慧仓库
  Widget _getSmartWarehouseView() {
    return CustomTitleChartPage(
      title: '智慧仓库',
      child: Column(
        children: [
          _buildSmartWarehousePieChart(),
          _buildSmartWarehouseSplineAreaChart(),
        ],
      ),
    );
  }

  /// 标题左圆点
  Widget _buildTitleLeftDot() {
    return Container(
      height: 12.w,
      width: 4.w,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(2.w),
        gradient: const LinearGradient(
          colors: [
            Color(0xFF5F57DC),
            Color(0xFFB0ABFB),
          ],
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter,
        ),
      ),
    );
  }

  /// 重大危险 进度条标题
  Widget _buildHazardProgressTitle(String text) {
    const color = Color(0xFF495061);
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Text(
          text,
          style: TextStyle(color: color, fontSize: 14.w),
        ),
        Row(
          children: [
            Container(
              decoration: BoxDecoration(
                color: Colors.blue,
                borderRadius: BorderRadius.circular(7),
              ),
              width: 7.w,
              height: 7.w,
            ),
            AppGaps.hGap4,
            Text('已完成', style: TextStyle(color: color, fontSize: 14.w)),
            AppGaps.hGap4,
            Container(
              decoration: BoxDecoration(
                color: Colors.red,
                borderRadius: BorderRadius.circular(7),
              ),
              width: 7.w,
              height: 7.w,
            ),
            AppGaps.hGap4,
            Text('逾期', style: TextStyle(color: color, fontSize: 14.w))
          ],
        ),
      ],
    );
  }

  /// 重大危险 当前报警统计 图表右侧解释
  Widget _buildLegendItem(Color? color, String name, int count) {
    return Container(
      width: 100.w,
      height: 23.w,
      alignment: Alignment.center,
      // margin: EdgeInsets.only(top: 11.w),
      child: Row(
        children: [
          Container(
            width: 10.w,
            height: 10.w,
            margin: EdgeInsets.only(right: 5.w),
            padding: EdgeInsets.all(2.w),
            decoration: BoxDecoration(color: color, borderRadius: BorderRadius.circular(5.w)),
            child: Container(
              decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(5.w)),
            ),
          ),
          Text(
            name,
            style: TextStyle(fontSize: 12.w, fontWeight: FontWeight.w400, color: const Color(0xffA0A7B5)),
          ),
          const Spacer(),
          Text(
            '$count',
            style: TextStyle(
              fontSize: 12.sp,
              fontWeight: FontWeight.w400,
              color: Colors.black,
            ),
          ),
        ],
      ),
    );
  }

  /// 重大危险 当前报警统计
  Widget _buildRiskAnalysisInit() {
    return SizedBox(
      height: 85.w,
      child: charts.SfCircularChart(
        legend: charts.Legend(
          isVisible: true,
          position: charts.LegendPosition.right,
          overflowMode: charts.LegendItemOverflowMode.none,
          legendItemBuilder: (String name, dynamic series, dynamic point, int seriesIndex) {
            final item = controller.alarmData[seriesIndex];
            return _buildLegendItem(
              item.color,
              name,
              item.y.toInt(),
            );
          },
          toggleSeriesVisibility: false,
        ),
        annotations: [
          charts.CircularChartAnnotation(
            widget: Container(
              width: 56.w,
              height: 56.w,
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(50.w),
              ),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    '总数',
                    style: TextStyle(
                      fontSize: 12.w,
                      fontWeight: FontWeight.w400,
                      color: const Color(0xffA0A7B5),
                    ),
                  ),
                  Text(
                    '${controller.initRiskCount}',
                    style: TextStyle(fontSize: 16.w, fontWeight: FontWeight.w400, color: const Color(0xFF495061)),
                  ),
                ],
              ),
            ),
          ),
        ],
        series: <charts.CircularSeries>[
          charts.DoughnutSeries<ChartData, String>(
            dataSource: controller.alarmData,
            pointColorMapper: (ChartData data, _) => data.color,
            xValueMapper: (ChartData data, _) => data.x,
            yValueMapper: (ChartData data, _) => data.y,
            name: '园区资料文件',
            dataLabelSettings: const charts.DataLabelSettings(
              isVisible: false,
              labelPosition: charts.ChartDataLabelPosition.inside,
            ),
            radius: '100%',
            innerRadius: '65%',
            enableTooltip: true,
          ),
        ],
      ),
    );
  }

  /// 特殊作业 顶部
  Widget _buildSpecialWorkTop() {
    return Container(
      decoration: BoxDecoration(color: const Color(0x1A5C6DFF), borderRadius: BorderRadius.all(Radius.circular(8.w))),
      child: Padding(
        padding: EdgeInsets.all(10.w),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            _buildSpecialWorkTopItem(),
            CustomVerticalGradientLine(height: 24.w),
            _buildSpecialWorkTopItem(),
            CustomVerticalGradientLine(height: 24.w),
            _buildSpecialWorkTopItem(),
            CustomVerticalGradientLine(height: 24.w),
            _buildSpecialWorkTopItem(),
          ],
        ),
      ),
    );
  }

  /// 特殊作业 顶部 单个
  Widget _buildSpecialWorkTopItem() {
    const color = Color.fromARGB(255, 102, 116, 245);
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        const Text(
          '20',
          style: TextStyle(
            color: color,
            fontWeight: FontWeight.w500,
          ),
        ),
        AppGaps.vGap10,
        const Text(
          '未处理',
          style: TextStyle(
            color: color,
            fontWeight: FontWeight.w500,
          ),
        ),
      ],
    );
  }

  Widget _buildSpecialWorkColorTypeIndicator() {
    return CustomColorTypeIndicator(
      colors: List.generate(8, (index) => Colors.red),
      types: List.generate(8, (index) => '$index'),
    );
  }

  /// 特殊作业 图表
  Widget _buildSpecialWorkChart() {
    return Container();
  }

  /// 智慧仓库 饼图
  Widget _buildSmartWarehousePieChart() {
    return SizedBox(
      height: 137.w,
      child: charts.SfCircularChart(
        series: <charts.PieSeries<ChartData, String>>[
          charts.PieSeries<ChartData, String>(
            dataSource: controller.alarmData,
            xValueMapper: (ChartData data, _) => data.x,
            yValueMapper: (ChartData data, _) => data.y,
            dataLabelMapper: (ChartData data, _) => data.x,
            radius: '55%',
            dataLabelSettings: const charts.DataLabelSettings(
              isVisible: true,
              labelIntersectAction: charts.LabelIntersectAction.none,
              overflowMode: charts.OverflowMode.shift,
              showZeroValue: false,
              labelPosition: charts.ChartDataLabelPosition.outside,
              connectorLineSettings: charts.ConnectorLineSettings(type: charts.ConnectorType.curve),
            ),
          )
        ],
      ),
    );
  }

  /// 智慧仓库 折线图
  Widget _buildSmartWarehouseSplineAreaChart() {
    return SizedBox(
      height: 197.w,
      child: charts.SfCartesianChart(
        plotAreaBorderWidth: 0,
        primaryXAxis: charts.NumericAxis(
          interval: 1,
          majorGridLines: const charts.MajorGridLines(width: 0),
          edgeLabelPlacement: charts.EdgeLabelPlacement.shift,
        ),
        primaryYAxis: charts.NumericAxis(
          labelFormat: '{value}%',
          axisLine: const charts.AxisLine(width: 0),
          majorTickLines: const charts.MajorTickLines(size: 0),
        ),
        series: <charts.ChartSeries<ChartData, int>>[
          charts.SplineAreaSeries<ChartData, int>(
            dataSource: controller.alarmData,
            color: const Color.fromRGBO(75, 135, 185, 0.6),
            borderColor: const Color.fromRGBO(75, 135, 185, 1),
            borderWidth: 2,
            xValueMapper: (ChartData sales, _) => sales.y.toInt(),
            yValueMapper: (ChartData sales, _) => sales.y,
          ),
        ],
        tooltipBehavior: charts.TooltipBehavior(enable: true),
      ),
    );
  }
}
